﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using Microsoft.Extensions.Logging;

namespace Whu.BLM.News.Context
{
    public class DbInitializer
    {

        public static bool InitializeDb<T>(NewsSystemContext context, ILogger<T> log)
        {
            if (context.Database.EnsureCreated())
            {
                context.Users.AddRange(
                    new User
                    {
                        Username = "SalHe",
                        Passowrd = "qwertyuiop",
                        Email = "SalHe@qq.com",
                        UserGroup = UserGroup.Admin
                    },
                    new User
                    {
                        Username = "user001",
                        Passowrd = "123456",
                        Email = "xxxx@qq.com",
                    }
                );

                log.LogInformation("初始化数据库成功");
                return true;
            }
            log.LogInformation("数据库已存在，不需要初始化");
            return false;
        }
    }
}
